<template>
	<view class="follow-stores">
		<view v-if="exist">
			<view class="shop" v-for="(item,index) in data" :key="index">
				<view class="h-content">
					<image class="h-left order-icon" @click="navToStore(item.shid)" :src="item.shavatar" mode="aspectFill"></image>
					<view class="h-center">
						<view class="line1-text2 font30" @click="navToStore(item.shid)">
							{{item.shname}}
						</view>
						<view class="attention">
							{{item.shop_collect_nums}}人关注
						</view>

					</view>

					<view class="h-right">
						<image src="/static/imgs/people.png" mode="aspectFill" class="run"></image>
						<text class="time">{{item.distance}}米<text class="iconfont">&#xe626;</text></text>
					</view>

				</view>

				<view class="goods-list">
					<view v-for="(img,indexs) in item.proimgs" :key="indexs">
						<image :src="img.proimgs" mode="aspectFill" class="goods-img" @click="navToGoods(img.proid)"></image>
					</view>
				</view>
				<view class="del-btn">
					<button @click="del(item.shid,index)">删除</button>
				</view>
			</view>

		</view>
		
		<!-- 缺省页 start-->
		<view class="default-page" v-else>
			<image src="/static/imgs/defaultPage/guanzhudianpu.png" mode="aspectFill"></image>
			<view>
				您还没有关注任何店铺呦~
			</view>
			<view class="button">
				<button @click="switchTab('/pages/index/index')">首页</button>
			</view>
		</view>
		<!-- 缺省页 end-->
		<!-- <view class="shop">
			<view class="h-content">
				<image class="h-left order-icon" src="/static/imgs/order-icon1.png" mode=""></image>
				<view class="h-center">
					<text class="line1-text2 font30">瑞派宠物店</text>
					<text class="attention">9999人关注</text>
				</view>

				<view class="h-right">
					<image src="/static/imgs/people.png" mode="" class="run"></image>
					<text class="time">500米<text class="iconfont">&#xe626;</text></text>
				</view>

			</view>
			<view class="goods-list">
				<view class="" v-for="(img,index) in imgs" :key="index">
					<image :src="img" mode="aspectFill" class="goods-img"></image>
				</view>
			</view>
			<view class="del-btn">
				<button >删除</button>
			</view>
		</view> -->



	</view>
</template>

<script>
	export default {
		data() {
			return {
				LL: {},
				data: [],
				exist: true, // 缺省状态控制
				imgs: ['/static/imgs/myStore/image_1.png',
					'/static/imgs/myStore/image_2.png',
					'/static/imgs/myStore/image_3.png'
				]
			};
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.LL = uni.getStorageSync('lph-ll');
			// #endif
			this.getData();
			
		},
		onPullDownRefresh() {
			this.getData();
		},
		methods: {
			navToStore(id) {
				uni.navigateTo({
					url: `/pages/user/storedetails?shid=${id}`
				})
			},
			navToGoods(id) {
				uni.navigateTo({
					url: `/pages/detail/detail?proid=${id}`
				})
			},
			async getData() {
				if (!('long' in this.LL)) {
					this.LL.long = '22.621121';
					this.LL.lat = '114.113993';
				}
				let a = await this.$http.getAttentionListByUserid({
					lng: this.LL.long,
					lat: this.LL.lat
				});
				uni.stopPullDownRefresh();
				this.data = a.data;
				a.data.length == 0 ? this.exist = false : this.exist = true;
			},
			async del(id, index) {
				let a = await this.$http.delAttention({
					shopid: id
				});
				if (a.code == 200) {
					this.data.splice(index, 1);
					this.data.length == 0 ? this.exist = false : this.exist = true;
					uni.showToast({
						title: "删除商品收藏成功~~",
						icon: 'none'
					});
					return
				}
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
			},
			switchTab(url) {
				uni.switchTab({
					url
				})
			},

		},
	}
</script>


<style lang="scss" scoped>
	@import 'static/css/set.scss';
</style>
